package com.mdd.admin.tools;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 订单编号创建
 * @Description
 * @Author 幻速
 * @Date 2023/11/15 15:37
 **/
public class OrderNoUtils {
    /**
     * uuid生成订单编号
     * @param orderPrefix 订单前缀
     * @return 订单ID
     */
    public static String getOrderUUID(String orderPrefix) {
        String uuid = UUID.randomUUID().toString();
        return orderPrefix +
                "_" +
                uuid.replace("-", "");
    }

    /**
     * time生成订单编号
     * @param orderPrefix 订单前缀
     * @return 订单ID
     */
    public static String getOrderIdByTime(String orderPrefix) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String date = dateFormat.format(new Date());
        Random random = new Random();
        return orderPrefix +
                "_" +
                date +
                random.nextInt(900) +
                random.nextInt(100);
    }

    public static void main(String[] args) {
        System.out.println(getOrderUUID("otf1"));
        System.out.println(getOrderIdByTime("otf1"));
    }
}
